package com.yanqu.road.logic.service.impl;

import com.yanqu.road.logic.controller.ClientLog;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author wpj
 * @Date 2021/3/18
 */
@Service
public class ClientLogImpl {
    @Autowired
    private JdbcTemplate jdbcTemplate;


    public void save(List<ClientLog> list) {
        if (CollectionUtils.isNotEmpty(list)) {
            jdbcTemplate.batchUpdate("INSERT INTO client_log (appId,channelId,startupID,deviceID,deviceModel,rVersion,os," +
                            "osVersion,serverID,userID,openID,timestamping,loginID,pVersion,deltaTime,eventID,param,packageID,successful) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
                    list, list.size(), (ps, d) -> {
                        int i = 1;
                        ps.setString(i++, d.getAppId());
                        ps.setString(i++, d.getChannelID());
                        ps.setLong(i++, d.getStartupID());
                        ps.setString(i++, d.getDeviceID());
                        ps.setString(i++, d.getDeviceModel());
                        ps.setString(i++, d.getrV() == null ? d.getrVersion() : d.getrV());
                        ps.setString(i++, d.getOs());
                        ps.setString(i++, d.getOsV() == null ? d.getOsVersion() : d.getOsV());
                        ps.setString(i++, d.getServerID());
                        ps.setString(i++, d.getUserID());
                        ps.setString(i++, d.getOpenID());
                        ps.setLong(i++, d.getTimestamping());
                        ps.setString(i++, d.getLoginID());
                        ps.setString(i++, d.getpV() == null ? d.getpVersion() : d.getpV());
                        ps.setLong(i++, d.getDeltaTime());
                        ps.setString(i++, d.getEventID());
                        ps.setString(i++, d.getParam());
                        ps.setString(i++, d.getPackageID());
                        ps.setString(i++, d.getSuccessful());
                    });
        }
    }
}
